package com.cbb.lease.util;

import java.text.*;
import java.util.Calendar;

/**
 * @program: clms-eighth01
 * @description: 根据时间生成 唯一ID
 * @author: 陈斌斌
 * @create: 2021-07-24 20:50
 **/

public class uuIDBytime {

    private static final FieldPosition HELPER_POSITION = new FieldPosition(0);

    /** 时间：精确到秒 */
    private final static Format dateFormat = new SimpleDateFormat("YYYYMMddHHmmss");

    private final static NumberFormat numberFormat = new DecimalFormat("");

    private static int seq = 0;

    private static final int MAX = 9999;

    public static synchronized String generateSequenceNo(){

        Calendar rightNow = Calendar.getInstance();

        StringBuffer sb = new StringBuffer();

        dateFormat.format(rightNow.getTime(), sb, HELPER_POSITION);

        numberFormat.format(seq, sb, HELPER_POSITION);

        if (seq == MAX) {
            seq = 0;
        } else {
            seq++;
        }
        return sb.toString();
    }

    public String getUUID(){
        return generateSequenceNo();
    }
}
